// The sample robotarm model.  You should build a file
// very similar to this for when you make your model.

#pragma warning(disable : 4018)
#pragma warning(disable : 4267)
#pragma warning(disable : 4311)
#pragma warning(disable : 4312)
#pragma warning(disable : 4244)
#pragma warning(disable : 4305)

#include "modelerview.h"
#include "modelerapp.h"
#include "modelerdraw.h"
#include "particleSystem.h"

#include <FL/gl.h>
#include <cstdlib>

//using namespace std;

#define M_DEFAULT 2.0f
#define M_OFFSET 3.0f
#define P_OFFSET 0.3f
#define MAX_VEL 200
#define MIN_STEP 0.1


// This is a list of the controls for the RobotArm
// We'll use these constants to access the values 
// of the controls from the user interface.
enum RobotArmControls
{ 
	Ks, Kd, G, 
    NUMCONTROLS, 
};

void drawCircle(float);



// To make a RobotArm, we inherit off of ModelerView
class TinkerToys : public ModelerView 
{
public:
    TinkerToys(int x, int y, int w, int h, char *label) 
        : ModelerView(x,y,w,h,label) {}
    virtual void draw();
};

// We need to make a creator function, mostly because of
// nasty API stuff that we'd rather stay away from.
ModelerView* createTinkerToys(int x, int y, int w, int h, char *label)
{ 
    return new TinkerToys(x,y,w,h,label); 
}

// We'll be getting the instance of the application a lot; 
// might as well have it as a macro.
#define VAL(x) (ModelerApplication::Instance()->GetControlValue(x))



// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out RobotArm
void TinkerToys::draw()
{
    /* pick up the slider values */
	ModelerApplication::Instance()->GetParticleSystem()->setKs( VAL(Ks) );
	ModelerApplication::Instance()->GetParticleSystem()->setKd( VAL(Kd) );
	ModelerApplication::Instance()->GetParticleSystem()->setGravity( VAL(G));

    // This call takes care of a lot of the nasty projection 
    // matrix stuff
    ModelerView::draw();

    static GLfloat lmodel_ambient[] = {0.4,0.4,0.4,1.0};

	drawCircle(5.0);

    endDraw();
}

void drawCircle(float radius)
{
	const float DEG2RAD = 3.14159/180.0;
	
	glBegin(GL_LINE_LOOP);
	for (int i=0; i < 360; i++) {
		float degInRad = i*DEG2RAD;
		glVertex2f(radius * cos(degInRad), radius * sin(degInRad));
	}
	glEnd();
}

   
int main()
{
    ModelerControl controls[NUMCONTROLS ];
	
	controls[Ks] = ModelerControl("Ks", 0.0, 20.0, 0.1, 0.0);
	controls[Kd] = ModelerControl("Kd", 0.0, 20.0, 0.1, 0.0);
	controls[G] = ModelerControl("Gravity", 0.0, 10.0, 0.2, 3.8);

    // You should create a ParticleSystem object ps here and then
    // call ModelerApplication::Instance()->SetParticleSystem(ps)
    // to hook it up to the animator interface.
    
    ParticleSystem *ps = new ParticleSystem();
    // do some more particle system setup
    ModelerApplication::Instance()->SetParticleSystem(ps);

    ModelerApplication::Instance()->Init(&createTinkerToys, controls, NUMCONTROLS);

    return ModelerApplication::Instance()->Run();
}
